package com.cmsky.open.web.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cmsky.open.base.service.MenuService;
import com.cmsky.open.cms.service.CmsNodeService;
import com.cmsky.open.shop.model.ShopAreaInfo;
import com.cmsky.open.shop.model.ShopInfo;
import com.cmsky.open.shop.vo.query.ShopAreaInfoQuery;
import com.cmsky.open.user.model.UserInfo;
import com.cmsky.open.user.service.UserLoginService;

@Controller
@RequestMapping("/g/uc")
public class UserCenterController {
	private static final Logger logger = Logger.getLogger(UserCenterController.class);
	private UserLoginService userLoginService;
	private MenuService menuService;
	private CmsNodeService cmsNodeService;
	
	public void setMenuService(MenuService menuService) {
		this.menuService = menuService;
	}

	public void setCmsNodeService(CmsNodeService cmsNodeService) {
		this.cmsNodeService = cmsNodeService;
	}

	public void setUserLoginService(UserLoginService userLoginService) {
		this.userLoginService = userLoginService;
	}
	
	@ModelAttribute
	public void init(HttpServletRequest request,HttpServletResponse response,ModelMap model) {
		model.put("now", System.currentTimeMillis());
		model.put("headMenu", this.menuService.getNavigationMenu());
		model.put("goodsMenu", this.menuService.getGoodsClssfiyMenu());
	}
	
	@RequestMapping("/index")
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response) throws Exception {
		ModelAndView view ;
		UserInfo userInfo = this.userLoginService.getLoginedUser(request, response);
		if(null==userInfo){
			view = new ModelAndView("redirect:/g/toLg.do");
		}else{
			view = new ModelAndView("/g/userCenter");
			view.addObject("userInfo", userInfo);
		}
		return view;
	}
}
